<template>
  <div class="area_eidt_room">
    <!-- 编辑房间 -->
    <el-dialog
      width="50%"
      custom-class="customWidth"
      center
      :before-close="roomcloseDialog"
      title="编辑房间"
      :close-on-click-modal="false"
      :visible.sync="eidtroomDialogFormVisible"
    >
      <el-form
        :model="eidtroomataForm"
        :rules="eidtroomataRule"
        ref="eidtroomataForm"
        label-width="100px"
      >
        <el-form-item
          label="房间信息"
          prop="roomName"
        >
          <el-col
            :span="15"
            id="roominfoto"
          >
            <el-input
              v-model="eidtroomataForm.roominfo"
              size="mini"
              style="font-size:16px;"
              disabled
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item
          label="名称"
          prop="roomName"
        >
          <el-col :span="15">
            <el-input
              v-model="eidtroomataForm.roomName"
              size="mini"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item
          label="网关"
          prop="wanguang"
        >
          <el-col :span="15">
            <el-select
              clearable
              v-model="eidtroomataForm.wanguang"
              placeholder="请选择"
              size="mini"
              style="width:100%"
            >
              <el-option
                v-for="item in wanguangoption"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-form-item>
          <el-form-item
          label="操作"
        >
          <el-col :span="15">
             <el-button type="primary" @click="deleteonSubmit" size="mini" icon="el-icon-plus">新增设备</el-button>
          </el-col>
        </el-form-item>
      </el-form>
      <div class="check">
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==0?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.doorlockisuse">启用门锁</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="70px"
          >
            <el-form-item
              label="编号"
              prop="doorlocknumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.doorlocknumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="doorlocknumber"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.doorlockmodel"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in doorlockmodeloption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="doorlocktemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.doorlocktemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in doorlocktemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==0?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.watercontrolisuse">启用水控</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="70px"
          >
            <el-form-item
              label="编号"
              prop="waternumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.waternumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="watercontrol"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.watercontrol"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in watercontroloption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="watertemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.watertemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in watertemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <!-- 消费机 -->
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==1 || eidtroomataForm.roomType==3?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.consumptionisuse">启用消费</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="70px"
          >
            <el-form-item
              label="编号"
              prop="consumptionnumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.consumptionnumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="consumption"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.consumption"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in consumptionoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="consumptiontemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.consumptiontemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in consumptiontemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <!-- 门禁 -->
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==2?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.accesscontrolisuse">启用门禁</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="70px"
          >
            <el-form-item
              label="编号"
              prop="accesscontrolnumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.accesscontrolnumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="accesscontrol"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.accesscontrol"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in accesscontroloption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="accesscontrolemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.accesscontrolemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in accesscontroltemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <!-- 电控 -->
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==0?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.electroniccontrolisuse">启用电控</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="70px"
          >
            <el-form-item
              label="编号"
              prop="electroniccontrolnumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.electroniccontrolnumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="electroniccontrol"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.electroniccontrol"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in electroniccontrolopton"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="electroniccontroltemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.electroniccontroltemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in consumptiontemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <!-- 空调 -->
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==0?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.airconditioningisuse">启用空调</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="70px"
          >
            <el-form-item
              label="编号"
              prop="airconditioningnumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.airconditioningnumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="airconditioning"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.airconditioning"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in airconditioningoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参赛模板"
              prop="airconditioningtemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.airconditioningtemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in airconditioningtemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <!--归属终端 -->
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==0?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.terminalisuse">启用归属终端</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="70px"
          >
            <el-form-item
              label="编号"
              prop="terminalnumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.terminalnumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="terminal"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.terminal"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in terminaloptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="terminaltemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.terminaltemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in terminaltemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <!-- 无人售货 -->
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==4?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.unsoldisuse">启用无人售货</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="100px"
          >
            <el-form-item
              label="编号"
              prop="unsoldnumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.unsoldnumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="unsold"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.unsold"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in unsoldoptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="unsoldtemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.unsoldtemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in unsoldtemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <!-- 直饮水 -->
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==4?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.drinkingwaterisuse">启用直饮水</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="100px"
          >
            <el-form-item
              label="编号"
              prop="drinkingwaternumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.drinkingwaternumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="drinkingwater"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.drinkingwater"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in drinkingwateroptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="drinkingwatertemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.drinkingwatertemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in drinkingwatertemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
        <!-- 电吹风 -->
        <el-card
          class="box-card"
          style="width:45%"
          shadow="hover"
          v-if="eidtroomataForm.roomType==4?true:false"
        >
          <el-checkbox v-model="eidtroomataForm.hairdryerisuse">启用电吹风</el-checkbox>
          <el-form
            :model="eidtroomataForm"
            :rules="eidtroomataRule"
            ref="eidtroomataForm"
            label-width="100px"
          >
            <el-form-item
              label="编号"
              prop="hairdryernumber"
            >
              <el-col :span="18">
                <el-input
                  v-model="eidtroomataForm.hairdryernumber"
                  size="mini"
                ></el-input>
              </el-col>
            </el-form-item>
            <el-form-item
              label="型号"
              prop="hairdryer"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.hairdryer"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in hairdryeroption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item
              label="参数模板"
              prop="hairdryertemplate"
            >
              <el-col :span="18">
                <el-select
                  clearable
                  v-model="eidtroomataForm.hairdryertemplate"
                  placeholder="请选择"
                  size="mini"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in hairdryertemplateoption"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="eidtroomvisible ()">取消</el-button>
        <el-button
          type="primary"
          @click="eidtroomataFormSubmit()"
        >确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      eidtroomDialogFormVisible: false,
      buildingGuid: "",
      layers: "",
      areaGuid: "",
      roomGuid: "",
      terminalRequests: [],

      wanguangoption: [],

      doorlockmodeloption: [],
      doorlocktemplateoption: [],

      watercontroloption: [],
      watertemplateoption: [],
      // 无人售货
      unsoldoptions: [],
      unsoldtemplateoption: [],
      //直饮水
      drinkingwateroptions: [],
      drinkingwatertemplateoption: [],
      //电吹风
      hairdryeroption: [],
      hairdryertemplateoption: [],

      // 电控
      electroniccontrolopton: [],
      electroniccontroltemplateoption: [],

      //空调
      airconditioningoption: [],
      airconditioningtemplateoption: [],
      //归属终端
      terminaloptions: [],
      terminaltemplateoption: [],

      consumptionoption: [],
      consumptiontemplateoption: [],

      accesscontroloption: [],
      accesscontroltemplateoption: [],

      eidtroomataForm: {
        roominfo: "",
        roomName: "",
        wanguang: "",
        roomType: 0,
        roomCode: "",
        //电吹风
        hairdryer: "",
        hairdryernumber: "",
        hairdryerpkTerminalId: "",
        hairdryertemplate: "",

        //直饮水
        drinkingwater: "",
        drinkingwaternumber: "",
        drinkingwatertemplate: "",
        drinkingwaterpkTerminalId: "",
        //无人售货
        unsold: "",
        unsoldnumber: "",
        unsoldpkTerminalId: "",
        unsoldtemplate: "",
        // 归属终端
        terminal: "",
        terminalnumber: "",
        terminaltemplate: "",
        terminalpkTerminalId: "",
        //空调
        airconditioning: "",
        airconditioningnumber: "",
        airconditioningtemplate: "",
        airconditioningpkTerminalId: "",
        //电控
        electroniccontrol: "",
        electroniccontrolnumber: "",
        electroniccontroltemplate: "",
        electroniccontrolpkTerminalId: "",
        //门锁
        doorlocknumber: "",
        doorlockmodel: "",
        doorlocktemplate: "",
        doorpkTerminalId: "",
        //水控
        waterpkTerminalId: "",
        waternumber: "",
        watercontrol: "",
        watertemplate: "",
        //消费
        consumptionnumber: "",
        consumption: "",
        consumptiontemplate: "",
        consumptionpkTerminalId: "",

        //门禁
        accesscontrol: "",
        accesscontrolnumber: "",
        accesscontrolemplate: "",
        accesscontrolpkTerminalId: "",

        doorlockisuse: false,
        watercontrolisuse: false,
        electroniccontrolisuse: false,
        airconditioningisuse: false,
        terminalisuse: false,

        consumptionisuse: false,
        accesscontrolisuse: false,

        unsoldisuse: false,
        drinkingwaterisuse: false,
        hairdryerisuse: false
      },
      eidtroomataRule: {}
    };
  },
  computed: {
    updateDocumentClientHeight: {
      get() {
        return this.$store.state.common.updateDocumentClientHeight;
      }
    }
  },
  mounted() {
    console.log(this.updateDocumentClientHeight);
  },
  props: ["unitGuid"],
  methods: {
    deleteonSubmit(){

    },
    roomcloseDialog(done) {
      // if (this.$refs['eidtroomataForm']!==undefined) {
      //   this.$refs['eidtroomataForm'].resetFields()
      // }
      done();
    },
    eidtroomvisible() {
      this.eidtroomDialogFormVisible = false;
      // this.$refs["eidtroomataForm"].resetFields();
    },
    eidtroomataFormSubmit() {
      this.terminalRequests = [];
      // console.log(this.areaGuid)
      // console.log(this.buildingGuid)
      // console.log(this.eidtroomataForm.wanguang)
      // console.log(this.layers)
      // console.log(this.roomGuid)
      // console.log(this.unitGuid)
      if (this.roomType == 0) {
        if (this.eidtroomataForm.doorlockisuse == true) {
          if (
            this.eidtroomataForm.doorlocknumber == "" ||
            this.eidtroomataForm.doorlockmodel == ""
          ) {
            this.$message({
              message: "门锁数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (this.eidtroomataForm.watercontrolisuse == true) {
          if (
            this.eidtroomataForm.waternumber == "" ||
            this.eidtroomataForm.watercontrol == ""
          ) {
            this.$message({
              message: "水控数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (this.eidtroomataForm.electroniccontrolisuse == true) {
          if (
            this.eidtroomataForm.electroniccontrolnumber == "" ||
            this.eidtroomataForm.electroniccontrol == ""
          ) {
            this.$message({
              message: "电控数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (this.eidtroomataForm.airconditioningisuse == true) {
          if (
            this.eidtroomataForm.airconditioningnumber == "" ||
            this.eidtroomataForm.airconditioning == ""
          ) {
            this.$message({
              message: "空调数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (this.eidtroomataForm.terminalisuse == true) {
          if (
            this.eidtroomataForm.terminalnumber == "" ||
            this.eidtroomataForm.terminal == ""
          ) {
            this.$message({
              message: "归宿终端数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (
          this.eidtroomataForm.doorpkTerminalId !== "" ||
          this.eidtroomataForm.doorlockisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.doorlockisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.doorpkTerminalId,
            terminalType: 22,
            terminalModel: this.eidtroomataForm.doorlockmodel,
            templateGuid: this.eidtroomataForm.doorlocktemplate,
            terminalCode: this.eidtroomataForm.doorlocknumber
          });
        }
        if (
          this.eidtroomataForm.waterpkTerminalId !== "" ||
          this.eidtroomataForm.watercontrolisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.watercontrolisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.waterpkTerminalId,
            terminalType: 6,
            terminalModel: this.eidtroomataForm.watercontrol,
            templateGuid: this.eidtroomataForm.watertemplate,
            terminalCode: this.eidtroomataForm.waternumber
          });
        }

        if (
          this.eidtroomataForm.electroniccontrol !== "" ||
          this.eidtroomataForm.electroniccontrolisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.electroniccontrolisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.electroniccontrolpkTerminalId,
            terminalType: 23,
            terminalModel: this.eidtroomataForm.electroniccontrol,
            templateGuid: this.eidtroomataForm.doorlocktemplate,
            terminalCode: this.eidtroomataForm.electroniccontrolnumber
          });
        }

        if (
          this.eidtroomataForm.airconditioningpkTerminalId !== "" ||
          this.eidtroomataForm.airconditioningisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.airconditioningisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.airconditioningpkTerminalId,
            terminalType: 24,
            terminalModel: this.eidtroomataForm.airconditioning,
            templateGuid: this.eidtroomataForm.electroniccontroltemplate,
            terminalCode: this.eidtroomataForm.airconditioningnumber
          });
        }
        if (
          this.eidtroomataForm.terminalpkTerminalId !== "" ||
          this.eidtroomataForm.terminalisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.terminalisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.terminalpkTerminalId,
            terminalType: 25,
            terminalModel: this.eidtroomataForm.terminal,
            templateGuid: this.eidtroomataForm.terminaltemplate,
            terminalCode: this.eidtroomataForm.terminalnumber
          });
        }
      }
      if (this.roomType == 2) {
        if (this.eidtroomataForm.accesscontrolisuse == true) {
          if (
            this.eidtroomataForm.accesscontrol == "" ||
            this.eidtroomataForm.accesscontrolnumber == ""
          ) {
            this.$message({
              message: "门禁数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (
          this.eidtroomataForm.accesscontrolpkTerminalId !== "" ||
          this.eidtroomataForm.accesscontrolisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.accesscontrolisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.accesscontrolpkTerminalId,
            terminalType: 21,
            terminalModel: this.eidtroomataForm.accesscontrol,
            templateGuid: this.eidtroomataForm.accesscontrolemplate,
            terminalCode: this.eidtroomataForm.accesscontrolnumber
          });
        }
      }
      if (this.roomType == 1 || this.roomType == 3) {
        if (this.eidtroomataForm.consumptionisuse == true) {
          if (
            this.eidtroomataForm.consumption == "" ||
            this.eidtroomataForm.consumptionnumber == ""
          ) {
            this.$message({
              message: "消费机数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (
          this.eidtroomataForm.consumptionpkTerminalId !== "" ||
          this.eidtroomataForm.consumptionisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.consumptionisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.consumptionpkTerminalId,
            terminalType: 1,
            terminalModel: this.eidtroomataForm.consumption,
            templateGuid: this.eidtroomataForm.consumptiontemplate,
            terminalCode: this.eidtroomataForm.consumptionnumber
          });
        }
      }
      if (this.roomType == 4) {
        if (this.eidtroomataForm.unsoldisuse == true) {
          if (
            this.eidtroomataForm.unsold == "" ||
            this.eidtroomataForm.unsoldnumber == ""
          ) {
            this.$message({
              message: "无人售货机数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (this.eidtroomataForm.drinkingwaterisuse == true) {
          if (
            this.eidtroomataForm.drinkingwater == "" ||
            this.eidtroomataForm.drinkingwaternumber == ""
          ) {
            this.$message({
              message: "直饮水数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (this.eidtroomataForm.hairdryerisuse == true) {
          if (
            this.eidtroomataForm.hairdryer == "" ||
            this.eidtroomataForm.hairdryernumber == ""
          ) {
            this.$message({
              message: "电吹风数据不合法",
              type: "warning"
            });
            return;
          }
        }
        if (
          this.eidtroomataForm.unsoldpkTerminalId !== "" ||
          this.eidtroomataForm.unsoldisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.unsoldisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.unsoldpkTerminalId,
            terminalType: 26,
            terminalModel: this.eidtroomataForm.unsold,
            templateGuid: this.eidtroomataForm.unsoldtemplate,
            terminalCode: this.eidtroomataForm.unsoldnumber
          });
        }
        if (
          this.eidtroomataForm.drinkingwaterpkTerminalId !== "" ||
          this.eidtroomataForm.drinkingwaterisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.drinkingwaterisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.drinkingwaterpkTerminalId,
            terminalType: 27,
            terminalModel: this.eidtroomataForm.drinkingwater,
            templateGuid: this.eidtroomataForm.drinkingwatertemplate,
            terminalCode: this.eidtroomataForm.drinkingwaternumber
          });
        }
        if (
          this.eidtroomataForm.hairdryerpkTerminalId !== "" ||
          this.eidtroomataForm.hairdryerisuse
        ) {
          this.terminalRequests.push({
            isUse: this.eidtroomataForm.hairdryerisuse == true ? 1 : 0,
            pkTerminalId: this.eidtroomataForm.hairdryerpkTerminalId,
            terminalType: 28,
            terminalModel: this.eidtroomataForm.hairdryer,
            templateGuid: this.eidtroomataForm.hairdryertemplate,
            terminalCode: this.eidtroomataForm.hairdryernumber
          });
        }
      }

      console.log(this.terminalRequests);
      // return
      this.$http({
        url: this.$http.adornUrl("/area/room/update-room-info"),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            areaGuid: this.areaGuid,
            buildingGuid: this.buildingGuid,
            controllerGuid: this.eidtroomataForm.wanguang,
            layers: this.layers,
            limitNum: 10,
            roomGuid: this.roomGuid,
            roomType: this.roomType,
            terminalRequests: this.terminalRequests,
            roomName: this.eidtroomataForm.roomName
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.$message({
            type: "success",
            message: "编辑成功!",
            duration: 500,
            onClose: () => {
              this.$emit("eidtroomlist", this.layers);
            }
          });
          this.eidtroomDialogFormVisible = false;
        } else {
          this.$message.error(data.errorMessage);
        }
      });
      // this.$refs['eidtroomataForm'].validate((valid) => {
      //     if(valid){

      //     }
      //  })
    },
    eidtifo(val) {
      // console.log(val)
      this.areaGuid = val;
    },
    eidtroom(item, buldingname, buildingid, layers) {
      console.log(item);
      this.roomType = item.roomType;
      // this.eidtroomataForm.roomCode=item.roomCode
      // console.log(buldingname)
      this.eidtroomataForm.roomType = item.roomType;
      this.eidtroomataForm.roomName = item.roomName;
      this.buildingGuid = buildingid;
      this.layers = layers;
      this.roomGuid = item.roomGuid;
      this.eidtroomataForm.roominfo =
        "楼栋" +
        buldingname +
        "\xa0\xa0\xa0\xa0\xa0\xa0" +
        "房间号" +
        item.roomCode;
      this.eidtroomataForm.roomName = item.roomName;
      this.getroomterminallsit();
      this.getwanguangoption();
      if (this.roomType == 0) {
        this.terminalselect(22, this.doorlockmodeloption);
        this.terminalselect(6, this.watercontroloption);
        this.terminalselect(23, this.electroniccontrolopton);
        this.terminalselect(24, this.airconditioningoption);
        this.terminalselect(25, this.terminaloptions);

        this.terminaltemplate(22, this.doorlocktemplateoption);
        this.terminaltemplate(6, this.watertemplateoption);
        this.terminaltemplate(23, this.electroniccontroltemplateoption);
        this.terminaltemplate(24, this.airconditioningtemplateoption);
        this.terminaltemplate(25, this.terminaltemplateoption);
      }
      if (this.roomType == 1 || this.roomType == 3) {
        this.terminalselect(1, this.consumptionoption);
        this.terminaltemplate(1, this.consumptiontemplateoption);
      }
      if (this.roomType == 2) {
        this.terminalselect(21, this.accesscontroloption);
        this.terminaltemplate(21, this.accesscontroltemplateoption);
      }
      if (this.roomType == 4) {
        this.terminalselect(26, this.unsoldoptions);
        this.terminaltemplate(26, this.unsoldtemplateoption);
        this.terminalselect(27, this.drinkingwateroptions);
        this.terminaltemplate(27, this.drinkingwatertemplateoption);
        this.terminalselect(28, this.hairdryeroption);
        this.terminaltemplate(28, this.hairdryertemplateoption);
      }
      setTimeout(() => {
        this.eidtroomDialogFormVisible = true;
      }, 100);
    },
    //获取房间设备详情
    getroomterminallsit() {
      this.$http({
        url: this.$http.adornUrl("/area/room/room-terminal-details"),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            roomGuid: this.roomGuid,
            roomType: 0
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          console.log(data);
          this.eidtroomataForm.wanguang = data.messageContent.controllerGuid;
          this.eidtroomataForm.doorlockmodel = "";
          this.eidtroomataForm.doorlocknumber = "";
          this.eidtroomataForm.doorpkTerminalId = "";
          this.eidtroomataForm.doorlockisuse = false;
          this.eidtroomataForm.doorlocktemplate = "";
          this.eidtroomataForm.airconditioningpkTerminalId = "";
          this.eidtroomataForm.airconditioning = "";
          this.eidtroomataForm.airconditioningnumber = "";
          this.eidtroomataForm.airconditioningtemplate = "";
          this.eidtroomataForm.airconditioningisuse = false;
          this.eidtroomataForm.waterpkTerminalId = "";
          this.eidtroomataForm.watercontrol = "";
          this.eidtroomataForm.waternumber = "";
          this.eidtroomataForm.watertemplate = "";
          this.eidtroomataForm.watercontrolisuse = false;
          this.eidtroomataForm.electroniccontrol = "";
          this.eidtroomataForm.electroniccontrolnumber = "";
          this.eidtroomataForm.electroniccontrolpkTerminalId = "";
          this.eidtroomataForm.electroniccontrolisuse = false;
          this.eidtroomataForm.electroniccontroltemplate = "";
          this.eidtroomataForm.terminal = "";
          this.eidtroomataForm.terminalnumber = "";
          this.eidtroomataForm.terminalpkTerminalId = "";
          this.eidtroomataForm.terminalisuse = false;
          this.eidtroomataForm.terminaltemplate = "";
          this.eidtroomataForm.unsold = "";
          this.eidtroomataForm.unsoldnumber = "";
          this.eidtroomataForm.unsoldpkTerminalId = "";
          this.eidtroomataForm.unsoldisuse = false;
          this.eidtroomataForm.unsoldtemplate = "";
          this.eidtroomataForm.drinkingwater = "";
          this.eidtroomataForm.drinkingwaternumber = "";
          this.eidtroomataForm.drinkingwaterpkTerminalId = "";
          this.eidtroomataForm.drinkingwaterisuse = false;
          this.eidtroomataForm.drinkingwatertemplate = "";
          this.eidtroomataForm.hairdryer = "";
          this.eidtroomataForm.hairdryernumber = "";
          this.eidtroomataForm.hairdryerpkTerminalId = "";
          this.eidtroomataForm.hairdryerisuse = false;
          this.eidtroomataForm.hairdryertemplate = "";
          this.eidtroomataForm.consumptionpkTerminalId = "";
          this.eidtroomataForm.consumption = "";
          this.eidtroomataForm.consumptionnumber = "";
          this.eidtroomataForm.consumptiontemplate = "";
          this.eidtroomataForm.consumptionisuse = false;
          this.eidtroomataForm.accesscontrolpkTerminalId = "";
          this.eidtroomataForm.accesscontrol = "";
          this.eidtroomataForm.accesscontrolnumber = "";
          this.eidtroomataForm.accesscontrolemplate = "";
          this.eidtroomataForm.accesscontrolisuse = false;
          for (
            var i = 0;
            i < data.messageContent.terminalRequests.length;
            i++
          ) {
            if (data.messageContent.terminalRequests[i].terminalType == 22) {
              this.eidtroomataForm.doorlockmodel =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.doorlocknumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.doorpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.doorlockisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
              this.eidtroomataForm.doorlocktemplate =
                data.messageContent.terminalRequests[i].templateGuid;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 24) {
              this.eidtroomataForm.airconditioningpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.airconditioning =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.airconditioningnumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.airconditioningtemplate =
                data.messageContent.terminalRequests[i].templateGuid;
              this.eidtroomataForm.airconditioningisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 6) {
              this.eidtroomataForm.waterpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.watercontrol =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.waternumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.watertemplate =
                data.messageContent.terminalRequests[i].templateGuid;
              this.eidtroomataForm.watercontrolisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 23) {
              this.eidtroomataForm.electroniccontrol =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.electroniccontrolnumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.electroniccontrolpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.electroniccontrolisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
              this.eidtroomataForm.electroniccontroltemplate =
                data.messageContent.terminalRequests[i].templateGuid;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 25) {
              this.eidtroomataForm.terminal =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.terminalnumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.terminalpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.terminalisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
              this.eidtroomataForm.terminaltemplate =
                data.messageContent.terminalRequests[i].templateGuid;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 26) {
              this.eidtroomataForm.unsold =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.unsoldnumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.unsoldpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.unsoldisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
              this.eidtroomataForm.unsoldtemplate =
                data.messageContent.terminalRequests[i].templateGuid;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 27) {
              this.eidtroomataForm.drinkingwater =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.drinkingwaternumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.drinkingwaterpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.drinkingwaterisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
              this.eidtroomataForm.drinkingwatertemplate =
                data.messageContent.terminalRequests[i].templateGuid;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 28) {
              this.eidtroomataForm.hairdryer =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.hairdryernumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.hairdryerpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.hairdryerisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
              this.eidtroomataForm.hairdryertemplate =
                data.messageContent.terminalRequests[i].templateGuid;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 1) {
              this.eidtroomataForm.consumptionpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.consumption =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.consumptionnumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.consumptiontemplate =
                data.messageContent.terminalRequests[i].templateGuid;
              this.eidtroomataForm.consumptionisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
            }
            if (data.messageContent.terminalRequests[i].terminalType == 21) {
              this.eidtroomataForm.accesscontrolpkTerminalId =
                data.messageContent.terminalRequests[i].pkTerminalId;
              this.eidtroomataForm.accesscontrol =
                data.messageContent.terminalRequests[i].terminalModel;
              this.eidtroomataForm.accesscontrolnumber =
                data.messageContent.terminalRequests[i].terminalCode;
              this.eidtroomataForm.accesscontrolemplate =
                data.messageContent.terminalRequests[i].templateGuid;
              this.eidtroomataForm.accesscontrolisuse =
                data.messageContent.terminalRequests[i].isUse == 1
                  ? true
                  : false;
            }
          }
        } else {
          this.$message.error(data.errorMessage);
        }
      });
    },
    getwanguangoption() {
      this.wanguangoption = [];
      this.$http({
        url: this.$http.adornUrl("/api/v1/device/controller-pithy"),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            buildingGuid: this.buildingGuid,
            layer: this.layers
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          console.log(data);
          let arr = data.messageContent;
          for (var i = 0; i < arr.length; i++) {
            let newobj = {
              label: arr[i].ip,
              value: arr[i].controllerGuid
            };
            this.wanguangoption.push(newobj);
          }
        } else {
          this.$message.error(data.errorMessage);
        }
      });
    },
    // 获取设备
    terminalselect(type, terminaloption) {
      this.$http({
        url: this.$http.adornUrl("/terminal/terminal-model-select"),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            terminalType: type,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        console.log(data);
        if (data.messageCode == 200) {
          let Arr = data.messageContent;
          if (terminaloption.length == 0) {
            for (var i = 0; i < Arr.length; i++) {
              var itemObj = {
                label: Arr[i].modelName,
                value: Arr[i].modelId,
                type: type
              };
              terminaloption.push(itemObj);
            }
            console.log(terminaloption);
          }
        } else {
          this.$message.error(data.errorMessage);
        }
      });
    },
    //获取设备模板
    terminaltemplate(type, templateoption) {
      this.$http({
        url: this.$http.adornUrl("/terminal/template-model-select"),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            terminalType: type,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        console.log(data);
        if (data.messageCode == 200) {
          let Arr = data.messageContent;
          if (templateoption.length == 0) {
            for (var i = 0; i < Arr.length; i++) {
              var itemObj = {
                label: Arr[i].templateName,
                value: Arr[i].templateGuid,
                type: type
              };
              templateoption.push(itemObj);
            }
            // console.log(templateoption)
          }
        } else {
          this.$message.error(data.errorMessage);
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.area_eidt_room {
  .el-form-item {
    margin-bottom: 10px;
  }
  .loudonginfo {
    font-size: 14px;
    // font-weight: bolder;
    padding-left: 10px;
    color: #303133;
    .loudong_name {
      margin-right: 20px;
    }
  }
  .check {
    border-top: 1px solid #e5e9f2;
    display: flex;
    justify-content: space-between;
    flex-flow: wrap;
  }
  .box-card {
    margin-top: 20px;
    padding-top: 10px;
    padding-left: 10px;
  }
}
</style>